<%@ page language="java" import="weaver.conn.RecordSet" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSetDataSource" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.jobs.common.DocUtil" %>
<%@ page import="java.util.Map" %>

<%
    String downloadpath = "http://192.168.15.80/netoffice//Pages/AttachStorageInfo/ReadAttachFile.aspx?AttachGuid=";
    User user = HrmUserVarify.getUser( request, response );
    String source = "oldoa";
    RecordSetDataSource rsd = new RecordSetDataSource(source);
    RecordSet rs = new RecordSet(  );
    rs.executeQuery("select id,shouwenfilenumber,txttitle from uf_dsjj_sw " +
            "where fj is null order by id");
    int counts1 = rs.getCounts();
    out.print( "<br>查询新系统收文总记录数为>>>>>>>["+counts1+"]<br/>");
    while (rs.next()) {
        String id = Util.null2String( rs.getString( "id" ) );
        String swwjh = Util.null2String( rs.getString( "shouwenfilenumber" ) );
        String title = Util.null2String( rs.getString( "txttitle" ) );
      /*  String sql = "select attachguid,attachfilename from frame_attachinfo where cliengguid in (" +
                "select ProcessVersionInstanceGuid from wd_25 " +
                "where 1=1 and TxtTitle='" + title + "' or ShouWenFileNumber='" + swwjh + "') order by uploaddatetime";*/
      String sql = "select t1.attachguid,t1.attachfilename,t.TxtTitle,t.ShouWenFileNumber from wd_25 t \n" +
              ", frame_attachinfo t1 where t1.UploadUserGuid=t.InitUserGuid \n" +
              "and substring(t1.attachfilename,0,CHARINDEX('.',t1.attachfilename))=t.TxtTitle\n" +
              "and t.TxtTitle='"+title+"'";
        rsd.execute( sql );
        int counts2 = rsd.getCounts();
        out.print( "<br>查询老系统收文附件总记录数为>>>>>>>["+counts2+"]<br/>");
        int count = 0;
        String docids = "";
        while (rsd.next()) {
            String attachguid = Util.null2String( rsd.getString( "attachguid" ) );
            String attachfilename = Util.null2String( rsd.getString( "attachfilename" ) );
            String downloadUrl = downloadpath + attachguid;
            out.print( "<br>下载地址----->" + downloadUrl );
            Map<String, Object> retMap = DocUtil.downloadByUrl( downloadUrl );
            if (!Util.null2String( retMap.get( "code" ) ).equals( "0" )) {
                out.print( "<br>" + attachfilename + "----->" + retMap.get( "msg" ) );
            } else {
                out.print( "<br>" + attachfilename + "----->" + retMap.get( "msg" ) );
                String filepath = Util.null2String( retMap.get( "data" ) );
                int imagefileid = DocUtil.saveImageFile( attachfilename, filepath );
                int docid = DocUtil.createDocByImagefileId( imagefileid, user, "1", "0", attachfilename, "", 1042);
                if(docid>0){
                    docids += docids.equals( "" ) ? docid : ("," + docid);
                    count++;
                }
            }
        }
        if(!"".equals( docids )){
            rs.executeUpdate("update uf_dsjj_sw set fj='"+docids+"' where id='"+id+"'");
        }
        out.print( "<br>查询同步附件记录数为>>>>>>>["+count+"]<br/>");
    }
%>
